package com.xiaoshuidi.cloud.module.rooms.controller.app.map;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.tenant.core.aop.TenantIgnore;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.map.vo.GetHFAdministrative;
import com.xiaoshuidi.cloud.module.rooms.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.rooms.service.BaiDuMapService;
import com.xiaoshuidi.cloud.module.rooms.service.RoomStreetLatlonService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.util.List;

@Slf4j
@Tag(name = "租客端 - 百度地图接口")
@RestController
@RequestMapping(ApiConstants.NAME + "/baidumap")
public class BaiDuMapAppController {

    @Resource
    private BaiDuMapService baiDuMapService;

    @Resource
    private RoomStreetLatlonService roomStreetLatlonService;

    /**
     * 获取合肥行政区域
     *
     * @return
     */
    @PermitAll
    @Operation(summary = "获取合肥行政区域")
    @GetMapping("/HF-administrative")
    @TenantIgnore
    public CommonResult<List<GetHFAdministrative>> getHFAdministrative() {
        return CommonResult.success(roomStreetLatlonService.getHFAdministrative());
    }

    @Operation(summary = "地点输入提示")
    @GetMapping("/location-entry-prompt")
    public CommonResult<JSONArray> locationEntryPrompt(String address, String coordType,String city){
        return CommonResult.success(baiDuMapService.locationEntryPrompt(address, coordType, city));
    }

    @PermitAll
    @Operation(summary = "百度逆地理位置编码")
    @GetMapping("/lat-lon-to-address")
    public CommonResult<JSONObject> latLonToAddress(String latLon) {
        // 租客端用的gps坐标系, 需要转换为百度bd09ll坐标系
        log.info("租客端-百度逆地理位置编码,请求经纬度:{}", latLon);
//        latLon = baiDuMapService.convertCoordinates(latLon);
        return CommonResult.success(baiDuMapService.latLonToAddress(latLon, "gcj02ll"));
    }
}
